"""
base_vector_db.py 模块
向量数据库基类
"""
from abc import ABC, abstractmethod
from typing import List, Tuple, Optional
from langchain.docstore.document import Document

class BaseVectorDB(ABC):
    """向量数据库基类，定义统一接口"""

    @abstractmethod
    def __init__(self, embedding, db_path: str, collection_name: str):
        """初始化向量数据库"""
        pass

    @abstractmethod
    def add_documents(self, documents: List[Document]) -> List[str]:
        """添加文档到向量数据库"""
        pass

    @abstractmethod
    def similarity_search(self, query: str, k: int = 4) -> List[Document]:
        """根据查询检索相似文档"""
        pass

    @abstractmethod
    def similarity_search_with_score(self, query: str, k: int = 4) -> List[Tuple[Document, float]]:
        """检索相似文档并返回相似度分数"""
        pass

    @abstractmethod
    def persist(self):
        """持久化向量数据库到磁盘"""
        pass

    @abstractmethod
    def close(self):
        """关闭数据库连接"""
        pass

    @classmethod
    @abstractmethod
    def load(cls, embedding, db_path: str, collection_name: str):
        """从磁盘加载向量数据库"""
        pass